package com.youbug.system.schedule;

import com.youbug.system.entity.Job;
import com.youbug.system.entity.Role;
import com.youbug.system.service.IJobService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.result.DefaultResultHandler;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import javax.sql.DataSource;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

@Component
@Slf4j
public class CopySysDataToRemoteDB {

    @Autowired
    @Qualifier("remoteSysJdbcTemplate")
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private IJobService iJobService;

//    @Scheduled(cron = "*/30 * * * * *")
    public void copySysData(){
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

        StackTraceElement stackTraceElement = stackTrace[1];

        String code = stackTraceElement.getMethodName();

//        System.out.println(code);

        Job job = iJobService.getJobByCode(code);

        if(ObjectUtils.isEmpty(job)){
//            log.error(code + "任务未配置");
            return;
        }
        List<Role> query = jdbcTemplate.query("select * from role", new BeanPropertyRowMapper<>(Role.class));

//        jdbcTemplate.+

//        System.out.println(query);
    }
}